﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.Sql;
using System.Reflection;
using System.Data.SqlClient;
using System.Configuration;
using SiteManager;
namespace docinternational
{
    public partial class SBSSearchForm : System.Web.UI.Page
    {
        Manager mgr = new Manager(true, "ConnectionString");
        localFunction lfunc = new localFunction();
         //string localConnect_old = @"Data Source=SBS-0SIZCRA2UA9\SQLEXPRESS;User ID=pdonovan;Password=DocDoc;Trusted_Connection=false;Initial Catalog=DOC";
        string localConnect_old = @"server=184.172.129.250;database=dbhaelthcare-dev;uid=findadoc;pwd=findadoc!@#$%;pooling=false;MultipleActiveResultSets=True;Min Pool Size=20;Max Pool Size=500;Connection Timeout=500"; 
        string localConnect = @"server=FINDADOCINC;database=dbhaelthcare-dev;uid=findadoc;pwd=findadoc!@#$%;pooling=false;MultipleActiveResultSets=True;Min Pool Size=20;Max Pool Size=500;Connection Timeout=500";
        string remoteConnect =ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;// @"server=FINDADOCINC;database=dbhaelthcare-dev;uid=findadoc;pwd=findadoc!@#$%;pooling=false;MultipleActiveResultSets=True;Min Pool Size=20;Max Pool Size=500;Connection Timeout=500";
        public bool isLive = false;
        protected void Page_Load(object sender, EventArgs e)
        {
            //connect first
            /*string fullCmd = " Select * from ACC_COUNTRIES ORDER BY NAME ";
            SqlDataAdapter ad = new SqlDataAdapter(fullCmd, localConnect);

            DataSet ds = new DataSet();
            ad.Fill(ds, "ACC_COUNTRIES");
            DataTable dt = ds.Tables[0];
            INTLOCS.Text += "<select name=\"INTLOCS\" size=\"1\" >\n";
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                DataRow drow = dt.Rows[i];
                string val = drow["ID"].ToString();
                string txt = drow["Name"].ToString();
                //if (val.Length > 0)
                  //  if (Char.IsLetter(val, 0))

                INTLOCS.Text += "<option value=\"" + val + "\">" + txt + "</option>\n";
            }
            //LOCS.Text += "<option value='BOSTON - ALLSTON'>BOSTON - ALLSTON</option>\n";
            //LOCS.Text += "<option value='BOSTON - BRIGHTON'>BOSTON - BRIGHTON</option>\n";
            INTLOCS.Text += "</select>";*/
        }
        public String getLocation()
        {                        
            return INT_LOCS.SelectedValue;
            
        }
        protected void Button1_Click(object sender, EventArgs e)
        {

            //connect first
            string countrycode = INT_LOCS.SelectedValue; 
            string fullCmd = " Select * from ACC_COUNTRYDETAILS where countryID=" + countrycode + " ORDER BY Hospital ";
            string conn = "";
            if (this.isLive == true)
                conn = remoteConnect;
            else
                conn = localConnect;
            SqlDataAdapter ad = new SqlDataAdapter(fullCmd, localConnect);

            DataSet ds = new DataSet();
            ad.Fill(ds, "ACC_COUNTRYDETAILS");
           DataTable dt = ds.Tables[0];
            System.Text.StringBuilder resultSet = new System.Text.StringBuilder();
            resultSet.Append("<table width=\"100%\" >");
            //title
            //resultSet.Text += "<td colspan=\"4\">" + country + "
            resultSet.Append("<style type=\"text/css\" media=\"screen\">");
            resultSet.Append(".sbsResults {");
            resultSet.Append(".sbsResultsTitle {");
            resultSet.Append(" background:#FFCC99;)");
            resultSet.Append("}");
            resultSet.Append("font-family: Verdana, Arial, Helvetica, sans-serif;font-size: 9px;color: #6B6B6B;}");
            resultSet.Append("#mainBlock { background:#E9E9E9; }");
            resultSet.Append("#mainBlockAlt { background:#F5F5F5;}");
            resultSet.Append("</style>");
            resultSet.Append("<tr height=\"15\"><td width=\"25%\" class='sbsResultsTitle'>Title</td>");
            resultSet.Append("<td width=\"25%\" class='sbsResultsTitle'>Description</td>");
            resultSet.Append("<td width=\"25%\" class='sbsResultsTitle'>Program</td>");
            resultSet.Append("<td width=\"25%\" class='sbsResultsTitle'>First Accredited</td>");

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                DataRow drow = dt .Rows[i];

                resultSet.Append("<tr>");
                string css = "mainBlock";
                if (i % 2 == 0)
                    css = "mainBlockAlt";

                string hosp = drow["Hospital"].ToString();
                string title = drow["Title"].ToString();
                string prog = drow["Program"].ToString();
                string firstacc = drow["FirstAccredited"].ToString();
                resultSet.Append("<td id=\"" + css + "\">" + hosp + "</td>");
                resultSet.Append("<td id=\"" + css + "\">" + title + "</td>");
                resultSet.Append("<td id=\"" + css + "\">" + prog + "</td>");
                resultSet.Append("<td id=\"" + css + "\">" + firstacc + "</td>");
                resultSet.Append("</tr>");
            }
            resultSet.Append("</table >");
            Response.Write(resultSet.ToString());
        }

        protected void SqlDataSource1_Selecting(object sender, SqlDataSourceSelectingEventArgs e)
        {

        }
       
    }
}
